package com.dingzhen.service;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author dingzhen
 */
@Service
public class ServiceFactory {

    private final Map<String, IService> map = new ConcurrentHashMap<>();

    public ServiceFactory(List<IService> serviceProvider) {
        serviceProvider.forEach(s -> map.put(s.type(), s));
    }

    public IService getService(String type) {
        return map.get(type);
    }
}
